/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-01-29
 * Time: 17:00
 */
public class Sort {
    // 选择排序
    public static void selectSort(int[] array){
        for (int i = 0; i < array.length; i++) {
            int tmp=i;
            for (int j = i+1; j <array.length ; j++) {
                if(array[j]<array[tmp]){
                    tmp=j;
                }
            }
            swap(array,i,tmp);
        }

 }
 private static  void swap(int[] array,int i,int j){
        int tmp=array[i];
        array[i]=array[j];
        array[j]=tmp;

 }
public static  void selectSort2(int[] array){
        int left=0;
        int right=array.length-1;
        while(left<right) {
            int minIndex = left;
            int maxIndex = left;
            for (int i = left + 1; i <= right; i++) {
                if (array[i] > array[maxIndex]) {
                    maxIndex = i;
                }
                if (array[i] < array[minIndex]) {
                    minIndex = i;
                }

            }
            swap(array, minIndex, left);
            if (maxIndex == left) {
                maxIndex = minIndex;
            }
            swap(array, maxIndex, right);
            left++;
            right--;
        }
}

// 堆排序
    public static void heapSort(int[] array){


}
}
